package bsts.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Feature implements Serializable {

	private static final long serialVersionUID = 1L;

	private long featureId;
	private String name;
	private String description;
	private double rate;
	private RateType rateType;
	private SubscriptionStatus subscriptionStatus;
	private Date dateCommenced;
	private Date dateTerminated;
	private boolean defaultFeature;

	public Feature(long featureId, String name, String description,
			double rate, RateType rateType, boolean defaultFeature) {
		this.featureId = featureId;
		this.name = name;
		this.description = description;
		this.rate = rate;
		this.rateType = rateType;
		this.defaultFeature = defaultFeature;
	}

	public Feature(String name, String description, double rate,
			RateType rateType, boolean defaultFeature) {
		this.name = name;
		this.description = description;
		this.rate = rate;
		this.rateType = rateType;
		this.defaultFeature = defaultFeature;
	}

	public boolean isDefaultFeature() {
		return defaultFeature;
	}

	public void setDefaultFeature(boolean defaultFeature) {
		this.defaultFeature = defaultFeature;
	}

	public long getFeatureId() {
		return featureId;
	}

	public void setFeatureId(long featureId) {
		this.featureId = featureId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getRate() {
		return rate;
	}

	public void setRate(double rate) {
		this.rate = rate;
	}

	public RateType getRateType() {
		return rateType;
	}

	public void setRateType(RateType rateType) {
		this.rateType = rateType;
	}

	public SubscriptionStatus getSubscriptionStatus() {
		return subscriptionStatus;
	}

	public void setSubscriptionStatus(SubscriptionStatus subscriptionStatus) {
		this.subscriptionStatus = subscriptionStatus;

		if (this.subscriptionStatus.equals(SubscriptionStatus.Terminated))
			this.setDateTerminated(new Date());
		else {
			this.setDateCommenced(new Date());
		}
	}

	public Date getDateCommenced() {
		return dateCommenced;
	}

	public String getStrDateCommenced() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		if (getDateCommenced() == null)
			return "";

		return sdf.format(getDateCommenced());
	}

	public void setDateCommenced(Date dateCommenced) {
		this.dateCommenced = dateCommenced;
	}

	public Date getDateTerminated() {
		return dateTerminated;
	}

	public String getStrDateTerminated() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		if (getDateTerminated() == null)
			return "";

		return sdf.format(getDateTerminated());
	}

	public void setDateTerminated(Date dateTerminated) {
		this.dateTerminated = dateTerminated;
	}
}
